<template>
  <div>
    <hellometa />
    <el-button @click="getCount">取值 </el-button>
    <el-button @click="countAdd">增加</el-button>
    <el-button style="" @click="Return">返回</el-button>
  </div>
</template>

<script>
import metamask from "./meta";
export default {
  name: "firstpage",
  data() {
    return {
      count: null,
    };
  },
  created() {
    //this.getCount();
  },
  mounted() {
    console.log("dispatching getContractInstance");
    this.$store.dispatch("getContractInstance");
  },
  components: {
    hellometa: metamask,
  },
  methods: {
    async getCount() {
      /// console.log("输出"+this.$store.state.contractInstance().methods)

      if (typeof this.$store.state.contractInstance !== "function") {
        console.log("typeof this.$store.state.contractInstance !== function");
        await this.$store.dispatch("getContractInstance");
      }
      console.log("haha" , this.$store.state.contractInstance());
      let that = this
      await this.$store.state.contractInstance().countGet(function(err,res){
        that.count = res;
      });
       console.log("count = ",parseInt(this.count))
    },
    async countAdd(event) {
      
      await this.$store.state.contractInstance().countAdd({
        gas: 300000,
        from: this.$store.state.web3.coinbase
      },(res)=>{

      })
    },
    Return() {
      this.$router.push("/");
    },
  },
};
</script>